<?php

/**
 * docreatead.php
 * @package adServer
 * @filesource
 */

/*	Close the backdoor	*/
$curPage = strtoupper($_SERVER['PHP_SELF']);
if (isset($curPage) && strpos($curPage, 'INDEX.PHP') === false)
    header('Location:./index.php');


/*	Check if there is a form submitted	*/
if (isset($_POST['adType']) && isset($_POST['adDuration']) && isset($_POST['adStartOffset'])) {
    if ($session->loggedIn == true) {
        $error = '';
        $adType = $_POST['adType'];
        $adDuration = $_POST['adDuration'];
        $adStartOffset = $_POST['adStartOffset'];
        $adCampaign = $_POST['adCampaign'];
        $adLanguage = $_POST['adLanguage'];
        $adHtml = $_POST['adHtml'];
        if ((int)$adDuration < 1)
            $error .= 'The Ad duration needs to be minimum 1 second<br/>';
        if ((int)$adDuration > 120)
            $error .= "The Ad duration needs to be maximum 120 seconds<br/>";
        if (strlen($adHtml) < 15 || substr_count($adHtml, '<') < 2 ||
            substr_count($adHtml, '>') < 2)
            $error .= "The HTML doesnt seem to be valid<br/>";
        if ($error == '')
            $session->createAdUnit($adType, $adCampaign, $adDuration, $adStartOffset,
                $adHtml, $adLanguage);

    } else {
        $error = 'Illegal operation, please try again';
    }


    if ($error == '') {
        header("Location:./index.php?action=createad&adSuccess=true");
    } else {
        header("Location:./index.php?action=createad&adType=$adType&adDuration=$adDuration&adStartOffset=$adStartOffset&adCampaign=$adCampaign&adLanguage=$adLanguage&adHtml=$adHtml&msg=" .
            urlencode($error));
    }
}

?>